#include<bits/stdc++.h>
using namespace std;

int a[200005],b[200005],c[200005];

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin >> t;
    for(int k = 1; k <= t; k++)
    {
        int n,s = 0;
        bool h = 1;
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
        sort(a + 1,a + n + 1);
        for(int i = 2;i <= n;i++) if(a[i] == a[i - 1]) s += a[i];
        cout << s << endl;
    }
    return 0;
}
